import React, { Component } from "react";
import { TouchableOpacity, View } from "react-native";

class DelayTouchableOpacity extends React.Component
{
    constructor(props)
    {
        super(props)
        this.state = {
            disabled: true
        }
        this.lastClickTime = 0
    }

    onPress()
    {
        const clickTime = Date.now()
        if (!this.lastClickTime || Math.abs(this.lastClickTime - clickTime) > 1000)
        {  //350的时间可以延长，根据需要改变
            this.lastClickTime = clickTime
            if (this.props.onPress)
            {
                this.props.onPress()
            } else
            {
                return ''
            }

        }
    }

    render()
    {
        return (
            <TouchableOpacity
                onPress={this.onPress.bind(this)}
                activeOpacity={0.85}
                style={this.props.style}
                disabled={this.props.disabled}>
                {this.props.children}
            </TouchableOpacity>)
    }
}

export default DelayTouchableOpacity

